var mall = {}
mall = {
        //跑马灯
		ScrollText:function(){
			function ScrollText(content, btnPrevious, btnNext, autoStart) {
				  this.Delay = 10;
				  this.LineHeight = 20;
				  this.Amount = 1; //注意:LineHeight一定要能整除Amount.
				  this.Direction = "up";
				  this.Timeout = 2500;
				  this.ScrollContent = this.$(content);
				  this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
				  //this.ScrollContent.scrollTop = 0;
				  if (btnNext) {
					this.NextButton = this.$(btnNext);
					this.NextButton.onclick = this.GetFunction(this, "Next");
					this.NextButton.onmouseover = this.GetFunction(this, "Stop");
					this.NextButton.onmouseout = this.GetFunction(this, "Start");
				  }
				  if (btnPrevious) {
					this.PreviousButton = this.$(btnPrevious);
					this.PreviousButton.onclick = this.GetFunction(this, "Previous");
					this.PreviousButton.onmouseover = this.GetFunction(this, "Stop");
					this.PreviousButton.onmouseout = this.GetFunction(this, "Start");
				  }
				  this.ScrollContent.onmouseover = this.GetFunction(this, "Stop");
				  this.ScrollContent.onmouseout = this.GetFunction(this, "Start");
				  if (autoStart) {
					this.Start();
				  }
				}
				
				ScrollText.prototype.$ = function(element) {
				  return document.getElementById(element);
				}
				
				ScrollText.prototype.Previous = function() {
				  clearTimeout(this.AutoScrollTimer);
				  clearTimeout(this.ScrollTimer);
				  this.Scroll("up");
				}
				
				ScrollText.prototype.Next = function() {
				  clearTimeout(this.AutoScrollTimer);
				  clearTimeout(this.ScrollTimer);
				  this.Scroll("down");
				}
				
				ScrollText.prototype.Start = function() {
				  clearTimeout(this.AutoScrollTimer);
				  this.AutoScrollTimer = setTimeout(this.GetFunction(this, "AutoScroll"), this.Timeout);
				}
				
				ScrollText.prototype.Stop = function() {
				  clearTimeout(this.ScrollTimer);
				  clearTimeout(this.AutoScrollTimer);
				}
				
				ScrollText.prototype.AutoScroll = function() {
				  if (this.Direction == "up") {
					if (parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2) {
					  this.ScrollContent.scrollTop = 0;
					}
					this.ScrollContent.scrollTop += this.Amount;
				  } else {
					if (parseInt(this.ScrollContent.scrollTop) <= 0) {
					  this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
					}
					this.ScrollContent.scrollTop -= this.Amount;
				  }
				  if (parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0) {
					this.ScrollTimer = setTimeout(this.GetFunction(this, "AutoScroll"), this.Delay);
				  } else {
					this.AutoScrollTimer = setTimeout(this.GetFunction(this, "AutoScroll"), this.Timeout);
				  }
				}
				
				ScrollText.prototype.Scroll = function(direction) {
				  if (direction == "up") {
					if (this.ScrollContent.scrollTop == 0) {
					  this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
					}
					this.ScrollContent.scrollTop -= this.Amount;
				  } else {
					this.ScrollContent.scrollTop += this.Amount;
				  }
				  if (parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2) {
					this.ScrollContent.scrollTop = 0;
				  }
				  if (parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0) {
					this.ScrollTimer = setTimeout(this.GetFunction(this, "Scroll", direction), this.Delay);
				  }
				}
				
				ScrollText.prototype.GetFunction = function(variable, method, param) {
				  return function() {
					variable[method](param);
				  }
			}
				if(document.getElementById("jsfoot02")){
						var scrollup = new ScrollText("jsfoot02");
						scrollup.LineHeight = 48;        //单排文字滚动的高度
						scrollup.Amount = 1;            //注意:子模块(LineHeight)一定要能整除Amount.
						scrollup.Delay = 1;           //延时
						scrollup.Start();             //文字自动滚动
						scrollup.Direction = "up";   //默认设置为文字向上滚动
					}
				/*
					if(document.getElementById("jsfoot03")){
						var scrollup = new ScrollText("jsfoot03");
						scrollup.LineHeight = 392;        //单排文字滚动的高度
						scrollup.Amount = 1;            //注意:子模块(LineHeight)一定要能整除Amount.
						scrollup.Delay = 20;           //延时
						scrollup.Start();             //文字自动滚动
						scrollup.Direction = "up";   //默认设置为文字向上滚动
					}
					*/
		},
        //选项卡
		slider: function setTab(name, cursel, n) {
			for (i = 1; i <= n; i++) {
				var menu = document.getElementById(name + i);
				var con = document.getElementById(name + i + i);
				menu.className = i == cursel ? "hovertab30" : "normaltab30";
				con.className = i == cursel ? "dis" : "undis";
			}
		},
		index:function(){
			mall.ScrollText();
			mall.slider();
			
			var param_arr = ['chen_08','chen_20'];
			mall.setOrangeColor(param_arr);
			mall.formSubmit();
			
			$('.flexslider').flexslider({
				directionNav: true,
				pauseOnAction: false
			});
		},
		/*
		 * @method setOrangeColor 设置消费扶贫前三颜色以及排列序号
		 * @param {array} param_arr 渲染的选择器数组
		 * @return null 返回值：无
		 * @author wcj
		 * @time 2018-10-01 15:26:00
		 * 
		 */
		setOrangeColor: function(param_arr){
			var i;
			var length = param_arr.length;
			
			for(i=0 ; i<length ; i++){
				var li = $('.'+ param_arr[i] +'').find('li');
			
				li.each(function(index , ele){
					$(this).find('i').html(index + 1);
					
					if(index >= 0 && index<= 2){
						$(this).addClass('cmh25');
					} else {
						$(this).find('i').removeClass();
						$(this).find('i').addClass('order2');
					}
				});
			}		
		},
		/*
		 * $method formSubmit 消费扶贫搜索
		 * @param null
		 * @return null 
		 * @author wcj
		 * @time 2018-10-04 15:26:00
		 *
		 */
		formSubmit: function(){
			$(document).on('click','.poor-search',function(){
				$('#search_form').submit();
			});
		}

}

var shareConfig = {
	title : '海南爱心扶贫网 - 海南首个互联网+消费扶贫公益平台',
	description : '海南爱心扶贫网 - 海南首个互联网+消费扶贫公益平台',
	image : location.origin + '/static/imgs/logo.jpg'
};
//登陆弹窗
function hidediv() {
	document.getElementById("bg").style.display ='none';
	document.getElementById("bf_mask_con").style.display ='none';
}
function showdiv(){  
	$("#bg").css({"height":window.screen.availHeight});
	$("#bg").show();
 
	var st=$(document).scrollTop(); //页面滑动高度
	var objH=$("#bf_mask_con").height();//浮动对象的高度
	var ch=$(window).height();//屏幕的高度  
	var objT=Number(st)+(Number(ch)-Number(objH))/2;   //思路  浮动高度+（（屏幕高度-对象高度））/2
	$("#bf_mask_con").css("top",objT);
	 
	var sl=$(document).scrollLeft(); //页面滑动左移宽度
	var objW=$("#bf_mask_con").width();//浮动对象的宽度
	var cw=$(window).width();//屏幕的宽度  
	var objL=Number(sl)+(Number(cw)-Number(objW))/2; //思路  左移浮动宽度+（（屏幕宽度-对象宽度））/2
	$("#bf_mask_con").css("left",objL);
	$("#bf_mask_con").fadeIn("20000");//这里显示方式多种效果
}
//四舍五入保留2位小数（不够位数，则用0替补）
function keepTwoDecimalFull(num) {
	 var result = parseFloat(num);
	 if (isNaN(result)) result=0.00;
	 result = Math.round(num * 100) / 100;
	 var s_x = result.toString();
	 var pos_decimal = s_x.indexOf('.');
	 if (pos_decimal < 0) {
		 pos_decimal = s_x.length;
		 s_x += '.';
	 }
	 while (s_x.length <= pos_decimal + 2) {
		s_x += '0';
	 }
	 return s_x;
}
/*
 * 图片上传：生成图片列表
 * _btn		：当前点击上传的按钮
 * _result	：上传成功后返回的数据
 */
function generateImageList(_btn,_result){
	var imgPreview = $(_btn).parent().find('.img-preview:first'),inputImgUrl = imgPreview.find('input[type=hidden]:first');
	$('<div class="img-panel"></div>').append('<img src="'+ _result.data.url +'" alt="" />')
	.append('<i class="layui-icon layui-icon-close-fill"></i>').appendTo(imgPreview)
	.find('.layui-icon-close-fill').click(function(){
		$(this).parent().remove();
		inputImgUrl.val(getImgUrl(imgPreview));
	});
	inputImgUrl.val(getImgUrl(imgPreview));				
	
	function getImgUrl(_imgpanel){
		var arr=[];
		$.each(_imgpanel.find('img'),function(){ arr.push($(this).attr('src'));});
		return arr.join(',');
	};
}
function generateImageOne(_btn,_result){
	var imgPreview = $(_btn).parent().find('.img-preview:first');
	if(imgPreview){
		var imgPanelArr = imgPreview.find('.img-panel');
		if(imgPanelArr&&imgPanelArr.length>0) imgPanelArr.remove();
	}
	generateImageList(_btn,_result);
}
$.extend({
	formatLocation:function(code){
		var location = {province : 0,city : 0,area : 0};
		if(code){
			location.province = code - code%1e4;
			location.city = code - (code%1e4 ? code%1e2 : code);
			location.area = code%1e2 ? code : 0;
			if(location.city=='460400'){ //排除儋州市
				location.area = '460400';
			}
		}
		return location;
	},
	isMobileNumber: function(str) {
		if(str != undefined){
			str = str.replace(/\D/g,""); /* 替换手机号中的空格*/
		}
		return $.trim(str) !== '' && /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(str);
	},
	submitLoading:function (_layer) {
		var idxLoading = -1;
		if(!!_layer) {
			idxLoading = _layer.load(1, {shade: 0.3});
		}else if(!!layui) {
			layui.use('layer', function () {
				idxLoading = layui.layer.load(1, {shade: 0.3});
			});
		}
		return idxLoading;
	}
});
(function($){
    $.fn.extend({
        Pageination:function(options ){
			//面向对象的写法
			new page(this,options);
        },
		StartTiming:function(_text){
			var that = this;
			var txt = 's后重新发送';
			var timeCount = timeInterval;
			if(_text) txt=_text;
			$(that).attr("disabled", "true");
			$(that).text(timeCount + txt);
			$(that).addClass('sendmsg');
			var intervalintId = window.setInterval(doing, 1000);
			function doing(){
				if(timeCount==0){
					window.clearInterval(intervalintId);
					$(that).removeAttr("disabled");
					$(that).text('重新发送');
					$(that).removeClass('sendmsg');
					return true;
				}
				timeCount--;
				$(that).text(timeCount + txt);
			}
		}
    });
	var timeInterval = 60;
    var page = function(ele,options){
        if(options==null){
			console.error('分页参数异常!');
		}
        this.element=ele;
        this.options={
            pageIndex:1,//当前页数
            pageSize:15,//总记录
            pageCount:1,//总页数
			url:'',
          params:'',
            callback:function(){}
        };
        this.options=$.extend({},this.options,options);
        this.init();
    }
    //初始化对象
    page.prototype={
        init:function(){
            //初始化
			this.createHtml();
			this.bindEvent();
        },
        createHtml:function(){
            var that=this;
            var content="";
			var pageCount=Number(that.options.pageCount)||1;
            var pageIndex=Number(that.options.pageIndex)||1;
            var pageSize=Number(that.options.pageSize)||1;
			
			content += "<ul class=\"pagination\"><li>共<span class=\"pagination_total\">"+ pageSize +"</span>条</li>";
			content += "<li id=\"first\"><span>首页</span></li><li id=\"pre\"><span>‹</span></li>";
            //总页数小于6
            if(pageCount<6){
                for(var i=1; i<(pageCount+1);i++){
                    if(pageIndex==i)
                    content+=getActiveLi(i);
                    else
                    content+=getActionLi(i);
                }
            }else{//总页数大于6
                if(pageIndex<4){
                    for(var i=1; i<5;i++){
                    if(pageIndex==i)
                    content+=getActiveLi(i);
                    else
                    content+=getActionLi(i);
                    }
                    content += ". . .";
					content+=getActionLi(pageCount);
                }
                else if(pageIndex>pageCount-4){
                    content += getActionLi(1);
                    content += ". . .";
                    for(var i=pageCount-4; i<pageCount+1;i++){
                      if(pageIndex==i)
                      content+=getActiveLi(i);
                      else
                      content+=getActionLi(i);
                    }
                }
                else{
                    content += getActionLi(1);
                    content += ". . .";
                    for(var i=pageIndex-2; i< parseInt(pageIndex)+3;i++){
                      if(pageIndex==i)
                      content+=getActiveLi(i);
                      else
                      content+=getActionLi(i);
                    }
                    content += ". . .";
                    content += getActionLi(pageCount);
                }
            }
            //结尾工作
			content += "<li id=\"next\"><span>›</span></li>";
			content += "<li id=\"last\"><span>尾页</span></li>";
			content += "<li id=\"jump\" style=\"margin-left:20px;\">";
          if (that.options.params != '') {
            content += "	<form style=\"margin-top:-5px;\" action=\""+that.options.url+ '?' + that.options.params+"\" method=\"post\">";
          } else {
            content += "	<form style=\"margin-top:-5px;\" action=\""+that.options.url+"\">";
          }
			// content += "	<form style=\"margin-top:-5px;\" action=\""+that.options.url+"\">";
			content += "	共<span class=\"pagination_pages\">"+pageCount+"</span>页，跳至";
			content += "	<input type=\"number\" min=\"1\" max=\""+pageCount+"\" name=\"page\" class=\"pagination_go_page\" value=\""+pageIndex+"\" />页";
			content += "	<input type=\"submit\" value=\"确认\" class=\"pagination_go\" />";
			content += "</form></li>";
			content += "</ul>";
            that.element.html(content);
            
			function getActiveLi(_num){
				return "<li class=\"active\"><span>"+_num+"</span></li>";
			}
			function getActionLi(_num){
				return "<li><span>"+_num+"</span></li>";
			}
        },
        bindEvent:function(){ 
            var that=this;
            that.element .on('click','li',function(){
				var text=$(this).html(),id=$(this).attr("id");
				if(id=='jump') return true;
				var current = that.options.pageIndex;
				switch(id){
					case "next":
						current++;
						if(current>that.options.pageCount){
							current=that.options.pageCount;
						}
						break;
					case "last":
						current=that.options.pageCount;
						break;
					case "first":
						current=1;
						break;
					case "pre":
						current-=1;
						if(current<=0){
							current=1;
						}
						break;
					default:
						current= parseInt($(text).html());
						break;
				}
				if(current==that.options.pageIndex){ 
					return false;
				}
                that.options.pageIndex=current;
			  	if (that.options.params != '') {
					window.location.href = that.options.url+"?page="+current + '&' + that.options.params;
			  	} else {
					window.location.href = that.options.url+"?page="+current;
			  	}
            });
        }
    }
})(window.jQuery);
/* jump */
var APP = {
	isMobile() {
		var userAgentInfo = navigator.userAgent;
		var mobileAgents = [
			'Android',
			'iPhone',
			'SymbianOS',
			'Windows Phone',
			'iPad',
			'iPod'
		];
		var mobile_flag = false;
		//根据userAgent判断是否是手机
		for (var v = 0; v < mobileAgents.length; v++) {
			if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
				mobile_flag = true;
				break;
			}
		}
		var screen_width = window.screen.width;
		var screen_height = window.screen.height;
		//根据屏幕分辨率判断是否是手机
		if (screen_width < 500 && screen_height < 800) {
			mobile_flag = true;
		}
		return mobile_flag;
	},
	isWeiXin() {
		//判断是否是微信浏览器的函数
		//window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息，这个属性可以用来判断浏览器类型
		var ua = window.navigator.userAgent.toLowerCase();
		//通过正则表达式匹配ua中是否含有MicroMessenger字符串
		if (ua.match(/MicroMessenger/i) == 'micromessenger') {
			return true;
		} else {
			return false;
		}
	},
	jump() {
		var url = window.location.pathname;
		var isViewMobile = this.isMobile(); // true为手机端，false为PC端
		var isWap = url.indexOf('/wap'),isDemo = url.indexOf('/demo');
		if (isDemo >= 0) return;
		if (this.isWeiXin()) {
			if (url === '/m'|| url.indexOf('/m/') >= 0) {
				return;
			}
			if (isWap >= 0) {
				window.location = '//' + window.location.host + url.replace('/wap', '/m');
			} else if(url === '/' || url==='/index' || url==='/Index'){
                window.location = '//' + window.location.host + '/m';
            }else {
                window.location = '//' + window.location.host + url.replace('/index/', '/m/').replace('/Index', '/m');
            }
			return;
		}
		if (isViewMobile && isWap < 0) {
			if (url === '/'|| url==='/index' || url==='/Index') {
				window.location = '//' + window.location.host + '/wap';
			}else {
				window.location = '//' + window.location.host + url.replace('/index/', '/wap/').replace('/Index', '/wap');
			}
		} else if (!isViewMobile && isWap >=0) {
			window.location = '//' + window.location.host + url.replace('/wap', '/index');
		}
	},
	init() {
		this.jump()
	}
};
APP.init();